package com.ecy.quadratic.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.widget.EditText;
import android.widget.Toast;

import com.ecy.quadratic.R;
import com.ecy.quadratic.beans.user.User;
import com.ecy.quadratic.component.DaggerComicMainComponent;
import com.ecy.quadratic.manager.LoginManager;
import com.ecy.quadratic.reader.base.BaseActivity;
import com.ecy.quadratic.reader.component.AppComponent;
import com.ecy.quadratic.reader.utils.ToastUtils;
import com.ecy.quadratic.ui.contract.PostCommentContract;
import com.ecy.quadratic.ui.presenter.PostCommentPresenter;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import butterknife.Bind;
import butterknife.OnClick;


public class PostCommentActivity extends BaseActivity implements PostCommentContract.View {

    @Bind(R.id.et_community_content)
    EditText mEtPostCommunity;
    @Inject
    PostCommentPresenter mPresenter;
    private int type = 0;
    private String id = "";
    private Map<String, String> map = new HashMap<String, String>();

    public static void startActivity(Context context, int type, String id) {
        Intent intent = new Intent(context, PostCommentActivity.class);
        intent.putExtra("type", type);
        intent.putExtra("id", id);
        context.startActivity(intent);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_post_comment;
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerComicMainComponent.builder()
                .appComponent(appComponent)
                .build()
                .inject(this);
    }

    @Override
    public void initToolBar() {

    }

    @Override
    public void initData() {
        type = getIntent().getIntExtra("type", 1);
        id = getIntent().getStringExtra("id");
    }

    @Override
    public void configViews() {
        mPresenter.attachView(this);

    }

    @OnClick(R.id.tv_post_community_cancel)
    public void cancel() {
        finish();
    }

    @OnClick(R.id.tv_send)
    public void send() {
        User user = LoginManager.getInstance().getUser();
        mPresenter.postComment(type, id, "", LoginManager.getInstance().getUserJson(), mEtPostCommunity.getText().toString());
    }


    @Override
    public void showError() {
        ToastUtils.getSingleToast("发表失败", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void complete() {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.detachView();
        }
    }

    @Override
    public void postCommentSuccesful() {
        ToastUtils.getSingleToast("发表成功", Toast.LENGTH_SHORT).show();
        finish();
    }
}
